package com.lyj.sc.dynamicProgramming;

/**
 * @Author: liyangjing
 * @Date: 2022/06/28/21:30
 * @Description: 使用最小花费爬楼梯
 */
public class zuixiaohuafeipalouti {
    public int minCostClimbingStairs(int[] cost) {
        if(cost==null || cost.length==0){
            return 0;
        }
        if(cost.length==1){
            return cost[0];
        }
        int [] dp = new int[cost.length];
        dp[0]=cost[0];
        dp[1]=cost[1];
        for(int i=2;i<cost.length;i++){
            //给动态规划方程
            dp[i]=Math.min(dp[i-1],dp[i-2])+cost[i];
        }
        return Math.min(dp[cost.length-1],dp[cost.length-2]);
    }
}
